/*
 * Created on Sep 30, 2003
 * ViewPersonAction
 * Local Projects Database
 * (c) 2003 eRomania Gateway Association
 *
 */
package ro.gateway.aida.struts.action;

import java.util.Vector;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.tiles.actions.TilesAction;

import ro.gateway.aida.db.PersistenceManager;
import ro.gateway.aida.db.PersistenceToken;
import ro.gateway.aida.obj.db.PersonDB;
import ro.gateway.aida.usr.User;
import ro.gateway.aida.usr.UserUtils;
import ro.gateway.aida.utils.PageToken;
import ro.gateway.aida.utils.Utils;
import ro.xblue.translator.LanguageBean;
import ro.xblue.translator.TranslatorUtils;

/**
 * @author Mihai Postelnicu
 * ViewPersonAction
 * 
 *  *  
 */
public class ViewPersonAction extends TilesAction {
	public ActionForward execute(ActionMapping mapping, ActionForm form,
		HttpServletRequest request, HttpServletResponse response) {
		ServletContext sc = getServlet().getServletContext();

		PersistenceToken token = PersistenceManager.
			  tokenLookup( sc );
		LanguageBean lang_bean = TranslatorUtils.getCurrentLanguage(request, sc);
		String lang = lang_bean.language;
		PersonDB persdb = PersonDB.getManager(token);
		String mode = request.getParameter("mode");
		User user = UserUtils.getLogged(request, response);

		if (user == null) {
			return mapping.findForward("plslogin");
		}

		if ("view".equals(mode)) {
			String id = request.getParameter("id");

			if (id == null) {
				return mapping.findForward("error");
			}
		}

		Vector persons = persdb.getAll(user.getId());
		PageToken.tokenizeList( request,  sc, persons, "persons");
		            

		if ("widget".equals(mode)) {
			return mapping.findForward("perswidget");
		}
		Utils.setBreadCrumbs(request,"bc.person.list");	
		return mapping.findForward("perslist");
	}
}
